package com.lyb.spzx.manager.controller;

import com.lyb.spzx.manager.service.SysMenuService;
import com.lyb.spzx.model.dto.system.system.SysMenu;
import com.lyb.spzx.model.vo.common.Result;
import com.lyb.spzx.model.vo.common.ResultCodeEnum;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "菜单接口")
@RestController
@RequestMapping("admin/system/sysMenu")
public class SysMenuController {

    @Autowired
    SysMenuService sysMenuService;

    @Operation(summary = "查询所有菜单")
    @GetMapping("/findNodes")
    public Result<List<SysMenu>> findNodes(){

        List<SysMenu> list = sysMenuService.findNodes();
        return Result.build(list, ResultCodeEnum.SUCCESS);
    }

    @Operation(summary = "添加菜单")
    @PostMapping("/saveMenu")
    public Result saveMenu(@RequestBody SysMenu sysMenu){
        System.out.println("sysMenu = " + sysMenu);
        sysMenuService.saveMenu(sysMenu);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }

    @Operation(summary = "修改菜单")
    @PutMapping("/updateMenu")
    public Result updateMenu(@RequestBody SysMenu sysMenu){
        sysMenuService.updateMenu(sysMenu);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }

    @Operation(summary = "删除菜单")
    @DeleteMapping("/deleteMenu/{id}")
    public Result deleteMenu(@PathVariable(name = "id") Long id){
        sysMenuService.deleteMenu(id);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }
}
